package animator.phantom.renderer.param;

/*
    Copyright Janne Liljeblad 2006,2007,2008

    This file is part of Phantom2D.

    Phantom2D is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Phantom2D is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Phantom2D.  If not, see <http://www.gnu.org/licenses/>.
*/

import animator.phantom.renderer.ImageOperation;
import animator.phantom.renderer.EditorRendererInterface;
import animator.phantom.renderer.RenderNode;
import java.util.*;

/**
* A parameter that has a Vector of RenderNode instances in render flow as value. The name of the class comes from the fact 
* the ImageOperation wrapped in a RenderNode is the functional part and the one used when
* parameter is used. ImageOperations do not have ids. 
* <p>
* Parameter is often used to describe parent child releationships between nodes.
*/
public class IOPVectorParam extends Param
{
	//--- Value object.
	private Vector<Integer> iopNodeIDs = new Vector<Integer>();

	/**
	* No parameter constructor.
	*/
	public IOPVectorParam(){}

	/**
	* Returns the ImageOperations wrapped in nodes that have their ids saved here. 
	*/
	public Vector<ImageOperation> get()
	{
		System.out.println("Vector<ImageOperation> get()");
		Vector<ImageOperation> retVec = new Vector<ImageOperation>();
		for( Integer nodeID : iopNodeIDs )
		{
			RenderNode iopNode = EditorRendererInterface.getNode( nodeID.intValue() );
			if( iopNode != null )
			{
				retVec.add( iopNode.getImageOperation() );
				System.out.println("iopnode NOT null");
			}
			else System.out.println("iopnode == null");
		}

		return retVec;
	}

	/**
	* Sets value using ImageOperation instances to get nodes ids.
	*/
	public void set( Vector<ImageOperation> newChildren )
	{
		iopNodeIDs.clear();
		for( ImageOperation iop : newChildren )
		{
			RenderNode iopNode = EditorRendererInterface.getNode( iop );
			if( iopNode != null ) 
				iopNodeIDs.add( new Integer( iopNode.getID() ) );
		}
	}

	/**
	* Adds node id to Vector using ImageOperation instance to get node's id.
	*/
	public void add( ImageOperation iop )
	{
		RenderNode iopNode = EditorRendererInterface.getNode( iop );
		if( iopNode == null ) return;
		iopNodeIDs.add( new Integer( iopNode.getID() ) );
	}

	/**
	* Removes node id from Vector using ImageOperation instance to get node's id.
	*/
	public void remove( ImageOperation iop )
	{
		RenderNode iopNode = EditorRendererInterface.getNode( iop );
		if( iopNode == null ) return;
		int removeID =  iopNode.getID();
		Integer removeInteger = null;
		for( Integer nodeID : iopNodeIDs )
		{
			if( nodeID.intValue() == removeID )
				removeInteger = nodeID;
		}
		iopNodeIDs.remove( removeInteger );
	}

	/**
	* Returns true if contains node id using ImageOperation instance to get node's id.
	*/
	public boolean contains( ImageOperation iop )
	{
		RenderNode iopNode = EditorRendererInterface.getNode( iop );
		if( iopNode == null ) return false;
		int checkID = iopNode.getID();
		boolean contains = false;
		for( Integer nodeID : iopNodeIDs )
		{
			if( nodeID.intValue() == checkID )
				contains = true;
		}
		return contains;
	}
	/**
	* Sets value using Vector of node ids.
	*/
	public void setNodeIDs( Vector<Integer>  iopNodeIDs_ ){ iopNodeIDs = iopNodeIDs_; }
	/**
	* Returns value as Vector of node ids.
	*/
	public Vector<Integer> getNodeIDs(){ return iopNodeIDs; }
	/**
	* Prints debug info.
	*/
	public void printDebugInfo()
	{
		System.out.println( "IOPVectorParam, iopNodes count" + iopNodeIDs.size() );
	}

}//end class